<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    // let map1 = new Map([
    //   ['name', 'zhen'],
    //   ['age', 28],
    // ])
    // console.log(map1.get('name'))
    // let arr = [
    //   ['name', 'zhen'],
    //   ['age', 28],
    // ]
    // let map2 = new Map()
    // 数组入参的内部实现
    // arr.forEach(([key, value]) => {
    //   map2.set(key, value)
    // })
    // console.log(map2)

    // map转为对象
    let map = new Map()
    map.set('name', 'zhen')
    map.set('age', '28')
    console.log('初始map为==', map)
    console.log('下面开始转换=======')
    let mapToObj = (map) => {
      let obj = Object.create(null)
      for (let [key, value] of map) {
        obj[key] = value
      }
      return obj
    }

    let obj = mapToObj(map)
    console.log('map转obj==', obj)

    let objToMap = (obj) => {
      let map = new Map()
      let keys = Object.keys(obj)
      keys.forEach((item) => {
        map.set(item, obj[item])
      })
      return map
    }
    console.log('obj转map==', objToMap(obj))

    // weakMap
    // console.log('===强引用弱引用===')
    // let key = new Array(5 * 1024 * 1024)
    // let weakmap1 = new WeakMap()
    // weakmap1.set(key, '123')
    // key = null
    // console.log(weakmap1)

    let a = 0,
      b = 0
    let A = function (a) {
      A = function (b) {
        console.log(a, b)
        console.log(a + b++)
        console.log('b==', b)
      }
      console.log(a)
    }
    A(1) // 1
    A(2) // 3
  </script>
</html>
